    var ul = document.querySelector("#ul");

//添加json数据
    document.querySelector("#btn").addEventListener('click',function(){

        //获取姓名
        var a = document.querySelector("#a").value;
        console.log(a);

        //获取性别
        var b = document.querySelector("#b").value;
        console.log(b);

        //获取年龄
        var c = document.querySelector("#c").value;
        console.log(c);

       if (a == ""){
           alert("请输入正确的姓名")
       }else if(c == ""){
           alert("请输入正确的年龄")
       } else {

           //ajax代码
           var xmlhttp;
           if (window.XMLHttpRequest)
           {
               //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
               xmlhttp=new XMLHttpRequest();
           }
           else
           {
               // IE6, IE5 浏览器执行代码
               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
           xmlhttp.onreadystatechange=function()
           {
               if (xmlhttp.readyState==4 && xmlhttp.status==200)
               {
                   ul.innerHTML = "";
                   wn();


               }
           };
           xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addStudent?studentName="+a+"&sex="+b+"&age="+c,true);
           //xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
           xmlhttp.send();
           document.querySelector("#a").value = "";
           document.querySelector("#c").value = "";
       }

    });

//获取json数据
    function wn(){

        //ajax代码
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            // IE6, IE5 浏览器执行代码
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                var json = JSON.parse(xmlhttp.responseText);
                console.log(json.data);


                json = json.data;


                for(var i = 0 ; i<json.length ; i++){

                    var li1 = document.createElement("li");

                    var span3 = document.createElement("span");
                    span3.innerHTML = json[i].studentName;

                    var span4 = document.createElement("span");
                    span4.innerHTML = json[i].sex;

                    var span5 = document.createElement("span");
                    span5.innerHTML = json[i].age;

                    li1.appendChild(span3);
                    li1.appendChild(span4);
                    li1.appendChild(span5);

                    ul.appendChild(li1);



                }
            }
        };
        //xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addStudent?studentName="+a+"&sex="+b+"&age="+c,true);
        xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
        xmlhttp.send();

    }
    wn();


